package com.cheng.io.input;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 对象字节输入流
 * 将文件/网络中的字节序列反序列化为对象
 */
public class ObjectInputStreamTest01 {
    public static void main(String[] args) {
        try (
                ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("io/resources/object"));
        ) {
            Object object;
            if ((object = objectInputStream.readObject()) instanceof Date) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                System.out.println(simpleDateFormat.format(object));
            }
        } catch (IOException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
